<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\Dashboard;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use Encore\Admin\Grid;
use Encore\Admin\Widgets\Box;
use Encore\Admin\Widgets\Form;

use App\Models\Account\Loginst;

use Illuminate\Http\Request;
use App\Admin\Extra\Search\Html;

//用户统计
class LoginstController extends Controller
{

    // 用户登录次数统计
    public function loginTime()
    {
        return Admin::content(function($content){
		    $content->header('player login times');
		    $content->description('<develop user_logout>.  statistic player login times by account or uid.');

            // 添加面包屑导航 since v1.5.7
            $content->breadcrumb(
                ['text' => '首页', 'url' => '/'],
                ['text' => '存留', 'url' => '/admin/userst/remain']
            );

            
		    $content->row(Html::append([
                Html::button('图表统计', '/admin/loginst/','btn-goto'),
            ]));	

			$grid = Admin::grid(Loginst::class, function(Grid $grid){
                $grid->log_time('login date');
                
                //$max = $grid->model()->_max_count;
                $grid->column('column', 'login times');
                $grid->column('all', 'DAU.');
                $grid->column('show_1', '1 time');
                $grid->column('show_2', '2 time');
                $grid->column('show_3', '3 time');
                $grid->column('show_4', '4 time');
                $grid->column('show_5', '5 time');
                $grid->column('show_6', 'more time');
                $grid->filter(function ($filter) use($use_data) {

                    // 模糊查询 注意
			        //$filter->where(function($query){
                    //    //$aids = \App\Models\EMail::getAccountByName('', 'playerName');
                    //    //var_dump($aids);exit;
                    //    $query->where('title', 'like', 'T%');
                    //}, '邮件标题', 'title');

                    $filter->between('log_time', 'date')->date();

                    //$filter->disableIdFilter();
                });
                $grid->disableCreateButton();
                //$grid->disableExport();
                $grid->disableActions();
                $grid->disableRowSelector();
            });

            $content->row($grid->render());
        });
    }

    public function userConvRate(){
        return Admin::content(function($content){
		    $content->header('用户转化率');
		    $content->description('<develop user_logout>.  statistic player login times by account or uid.');

            // 添加面包屑导航 since v1.5.7
            $content->breadcrumb(
                ['text' => '首页', 'url' => '/'],
                ['text' => '存留', 'url' => '/admin/userst/remain']
            );

            
		    $content->row(Html::append([
                Html::button('图表统计', '/admin/loginst/','btn-goto'),
            ]));	

            $result = \App\ModelStatistic\UserConvRate::getConvTotalData();
            $content->row(Html::append([
                Html::button('打开游戏:' . $result['count_open'], '','btn-warning'),
                Html::button('创建账号:' . $result['count_account'], '','btn-info'),
                Html::button('创建角色:' . $result['count_role'], '','btn-success'),
            ]));	
            
            $use_data['stage_list'] = \App\ModelStatistic\UserConvRate::stageList();
            $use_data['area_online'] = \App\Models\Area::areaSelectData();
			$grid = Admin::grid(\App\ModelStatistic\UserConvRate::class, function(Grid $grid)use($use_data){
                
                
                //$max = $grid->model()->_max_count;
                $grid->column('area', 'Area');
                
                foreach ($use_data['stage_list'] as $opk => $alias) {

                    $grid->column(str_replace('.','___',$opk), $alias);
                }
                $grid->filter(function ($filter) use($use_data) {

                    // 模糊查询 注意
			        //$filter->where(function($query){
                    //    //$aids = \App\Models\EMail::getAccountByName('', 'playerName');
                    //    //var_dump($aids);exit;
                    //    $query->where('title', 'like', 'T%');
                    //}, '邮件标题', 'title');

                    $filter->between('select_time', 'date')->date();
                    $filter->equal('select_area')->select($use_data['area_online']);
                    //$filter->disableIdFilter();
                });
                $grid->disableCreateButton();
                //$grid->disableExport();
                $grid->disableActions();
                $grid->disableRowSelector();
            });

            $content->row($grid->render());
        });        
    }
}
